package com.example.personalizededucationsystem.dto.dto;

import com.example.personalizededucationsystem.model.ErrorNotebook;
import com.example.personalizededucationsystem.model.Question;
import lombok.Getter;
import lombok.Setter;

import java.time.Instant;

@Setter
@Getter
public class ErrorNotebookEntryResponseDto {
    private Long errorId;
    private Long questionId;
    private String questionContent;
    private int errorCount;
    private Instant lastErrorAt;
    private String status;

    public static ErrorNotebookEntryResponseDto fromEntity(ErrorNotebook errorNotebook) {
        ErrorNotebookEntryResponseDto dto = new ErrorNotebookEntryResponseDto();
        dto.setErrorId(errorNotebook.getErrorId());
        dto.setErrorCount(errorNotebook.getErrorCount());
        dto.setLastErrorAt(errorNotebook.getLastErrorAt());
        dto.setStatus(errorNotebook.getStatus());

        Question question = errorNotebook.getQuestion();
        if (question != null) {
            dto.setQuestionId(question.getQuestionId());
            dto.setQuestionContent(question.getContent());
        }
        return dto;
    }

}